package com.sam.designpatterns

import kotlin.concurrent.thread

interface IScreen {
    //点亮屏幕
    fun lightUp()
}

class IPhoneScreen : IScreen {
    override fun lightUp() {
        println("iPhone 小屏")
    }
}

class IPadScreen : IScreen {
    override fun lightUp() {
        println("iPad 大屏")
    }
}


interface ICpu {
    fun compute()
}
class IPhoneCpu : ICpu {
    override fun compute() {
        println("A14")
    }
}
class IPadCpu : ICpu {
    override fun compute() {
        println("A12Z")
    }
}

//抽象工厂
interface AbstractFactory {
    fun produceScreen(): IScreen
    fun produceCpu(): ICpu
}
class IPhoneFactory : AbstractFactory {
    override fun produceScreen(): IScreen {
        return IPhoneScreen()
    }

    override fun produceCpu(): ICpu {
        return IPhoneCpu()
    }
}
class IPadFactory : AbstractFactory {
    override fun produceScreen(): IScreen {
        return IPadScreen()
    }

    override fun produceCpu(): ICpu {
        return IPadCpu()
    }
}

fun main() {
    println("来到 IPhone 工厂")
    var factory: AbstractFactory = IPhoneFactory()
    var screen = factory.produceScreen()
    print("生产了：")
    screen.lightUp()
    var cpu = factory.produceCpu()
    print("生产了：")
    cpu.compute()

    println("来到 IPad 工厂")
    factory = IPadFactory()
    screen = factory.produceScreen()
    print("生产了：")
    screen.lightUp()
    cpu = factory.produceCpu()
    print("生产了：")
    cpu.compute()
}

